package com.vader.boot.beanPostProcessorTest;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.proxy.DruidDriver;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.sql.Driver;

/**
 * @author Vader
 * @date 2022/5/19
 **/
@Configuration
@ComponentScan("com.vader.boot.beanPostProcessorTest.component")
public class Config {

    @Bean
    public Bean1 bean1() {
        return new Bean1();
    }

    @Bean
    public SqlSessionFactoryBean SqlsessionFactoryBean(DataSource dataSource) {
        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
        sqlSessionFactoryBean.setDataSource(dataSource);
        return sqlSessionFactoryBean;
    }

    @Bean(initMethod = "init")
    public DruidDataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl("jdbc:mysql://rm-2zebq239wc2774s39eo.mysql.rds.aliyuncs.com:3306/fancy_content?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai");
        dataSource.setName("fancy_root");
        dataSource.setPassword("fancyApp666");
        dataSource.setDriver(DruidDriver.getInstance());
        return dataSource;
    }

}
